package com.jjb.www.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.base.BaseDialog;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.permissions.Permission;
import com.hjq.shape.layout.ShapeRecyclerView;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.aop.Permissions;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.CurriculumSortApi;
import com.jjb.www.http.api.PlanDetitleApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.ui.adapter.PlanDetailsAdapter;
import com.jjb.www.ui.dialog.PlanDialog;
import com.jjb.www.ui.dialog.PlanListDialog;
import com.jjb.www.ui.fragment.CourseListFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * author : Android CRG
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/10/18
 * desc   : 计划详情
 */
public class PlanDetitleActivity extends AppActivity {
    private ShapeTextView mTvClassTime;
    private ShapeTextView mTvDay;
    private ShapeImageView mImgPhoto;
    private ShapeTextView mTvMecName;
    private ShapeTextView mTvAddress;
    private ShapeRecyclerView mRvList;
    private AppCompatCheckBox mIvPayCheck;
    private ShapeTextView mTvSignUp;
    private PlanDetailsAdapter adapter;
    private ShapeImageView mTvCallPhone;
    private PlanDetitleApi.Bean.PlanInfoDTO bean;



//    private List<String> list = new ArrayList<>();
//    private List<String> planList = new ArrayList<>();
//    private Integer mPersion = 0;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_plan_detitle;
    }

    @Override
    protected void initView() {
        mTvClassTime = findViewById(R.id.tv_class_time);
        mTvDay = findViewById(R.id.tv_day);
        mTvCallPhone = findViewById(R.id.tv_call_phone);
        mImgPhoto = findViewById(R.id.img_photo);
        mTvMecName = findViewById(R.id.tv_mec_name);
        mTvAddress = findViewById(R.id.tv_address);
        mRvList = findViewById(R.id.rv_list);
        mIvPayCheck = findViewById(R.id.iv_pay_check);
        mTvSignUp = findViewById(R.id.tv_sign_up);
        adapter = new PlanDetailsAdapter(getContext());
        mRvList.setAdapter(adapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));

        setOnClickListener(mTvSignUp,mTvCallPhone);
    }

    @Permissions({Permission.CALL_PHONE})
    private void callPhone(String phone) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri data = Uri.parse("tel:" + phone);
        intent.setData(data);
        startActivity(intent);
    }
    @Override
    protected void initData() {
        EasyHttp.get(this)
                .api(new PlanDetitleApi()
                .setId(getString("id"))
                .setPlan_type(getString("plan_type")))
                .request(new HttpCallback<HttpData<PlanDetitleApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<PlanDetitleApi.Bean> data) {
                        bean = data.getData().getPlan_info();
                        mTvClassTime.setText(getString("className"));
                        mTvDay.setText("距离开班时间："+bean.getDay()+"天");
                        GlideApp.with(getContext())
                                .load(bean.getPhoto())
                                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                                .into(mImgPhoto);
                        mTvMecName.setText("机构名称："+bean.getMech_name());
                        mTvAddress.setText("机构地址："+bean.getSchool_address());
                        adapter.setData(data.getData().getPlan_info().getTime_list());
                    }

                });
    }

    @Override
    public void onClick(View view) {
        if (view==mTvCallPhone) {
            callPhone(bean.getUrgent_mobile());
        }
    }
}